home *** CD-ROM | disk | FTP | other *** search
- Path: news.inc.net!news
- From: Will Flor <willf@rrgroup.com>
- Newsgroups: comp.lang.c
- Subject: Re: Storing C Functions In An Array?
- Date: 28 Mar 1996 16:32:39 GMT
- Organization: R R Systems Group Inc.
- Message-ID: <4jeev7$7vf@news.inc.net>
- References: <4jc1u7$5e9@infa.central.susx.ac.uk>
- NNTP-Posting-Host: 204.95.173.139
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2N (Windows; I; 32bit)
-
- tepd6@central.susx.ac.uk (George Rattray) wrote:
- >Can someone help me, I'm trying to store functions in an array at
- >compile time. The following functions are defined as
- >
- > struct complex func(struct complex, CHNL);
- >
- >I want to store them in an array ch[N];
- >
- >Therefor using the function with an index as
- >
- > ret = ch[0](x,chnl);
- >
- >Any help will be most appreciated, Thanks
- >
- >George
- >
-
- You should store pointers to the functions, as I assume you know. Declare the
- array to be one of pointers to functions and assign using the common static
- "compile-time" array initialization, like so:
-
- struct complex (*ch[])(struct complex, CHNL) = { func1, func2, ... funcn }
-
- It's been a while since I wrote any code that did this, but I'm pretty sure this will
- work.
-
- -Will Flor willf@rrgroup.com
- The R R Systems Group, Inc. http://www.rrgroup.com/
-
-
-